/*************************************************************************
** Copyright (C) 2014  Mario Marquez <maqzma@gmail.com>.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/

#include "STestRunner.h"

#include <QtTest/QTest>

// WARNING: Uncomment to disable assertions.
// #define NDEBUG

#include <cassert>

STestRunner::STestRunner(int argc, char **argv, QObject *parent)
    : QObject(parent)
{
    _argc = argc;
    _argv = argv;

    _continuous = false;
}

void STestRunner::addTest(QObject *test)
{
    assert(test != nullptr);

    _tests.push_back(test);
}

void STestRunner::removeTest(QObject *test)
{
    assert(test != nullptr);

    _tests.removeAt(_tests.indexOf(test));
}

void STestRunner::setContinuous(bool continuous)
{
    _continuous = continuous;
}

bool STestRunner::continuous() const
{
    return _continuous;
}

void STestRunner::runTests()
{
    foreach (QObject *test, _tests)
    {
        if (QTest::qExec(test, _argc, _argv) != 0
                && _continuous == false)
        {
            // Si no es continuo rompe el bucle.
            break;
        }
    }
}
